-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "fs,win: fix bug in paths with trailing slashes" #55527
Conversation
This reverts commit 00b2f07.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55527 +/- ##
==========================================
- Coverage 88.42% 88.42% -0.01%
==========================================
Files 654 654
Lines 187552 187509 -43
Branches 36087 36075 -12
==========================================
- Hits 165839 165800 -39
+ Misses 14950 14947 -3
+ Partials 6763 6762 -1
|
From what I've seen, the problem is in patchdiff --git a/lib/fs.js b/lib/fs.js
index e6ae9855a0d..6207bef8c05 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -537,7 +537,8 @@ function closeSync(fd) {
* @returns {void}
*/
function open(path, flags, mode, callback) {
- path = getValidatedPath(path, 'path', { expectFile: true, syscall: 'open' });
+ const isDirectory = lstatSync(path, {throwIfNoEntry: false})?.isDirectory();
+ path = getValidatedPath(path, 'path', { expectFile: !isDirectory, syscall: 'open' });
if (arguments.length < 3) {
callback = flags;
flags = 'r';
@@ -565,8 +566,9 @@ function open(path, flags, mode, callback) {
* @returns {number}
*/
function openSync(path, flags, mode) {
+ const isDirectory = lstatSync(path, {throwIfNoEntry: false})?.isDirectory();
return binding.open(
- getValidatedPath(path, 'path', { expectFile: true, syscall: 'open' }),
+ getValidatedPath(path, 'path', { expectFile: !isDirectory, syscall: 'open' }),
stringToFlags(flags),
parseFileMode(mode, 'mode', 0o666),
);
diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js
index f5a9a3a8542..f029d28d752 100644
--- a/lib/internal/fs/promises.js
+++ b/lib/internal/fs/promises.js
@@ -633,7 +633,8 @@ async function copyFile(src, dest, mode) {
// Note that unlike fs.open() which uses numeric file descriptors,
// fsPromises.open() uses the fs.FileHandle class.
async function open(path, flags, mode) {
- path = getValidatedPath(path, 'path', { expectFile: true, syscall: 'open' });
+ const stats = await lstat(path);
+ path = getValidatedPath(path, 'path', { expectFile: !stats.isDirectory(), syscall: 'open' });
const flagsNumber = stringToFlags(flags);
mode = parseFileMode(mode, 'mode', 0o666);
return new FileHandle(await PromisePrototypeThen(
What do you think? |
I don't really like that you're doing a stat before I get to open the file descriptor, part of the reason one might deal directly with file descriptors is to be able to manage the lifecycle much more carefully. In the particular use-case where this error came up for me I'm doing precisely this - open fd, do a stat on it, deal with it in a particular way if it's a directory or not, but hold on to the fd for further operations later; a very fine-grained handling of the filesystem in a particularly i/o heavy situation. Your solution now wants to essentially load my file descriptor twice before I can get my hands on it. I'd also like errors to be dealt with via the callback if one is present, passing that down into |
This will probably also fix emscripten-core/emscripten#22812 |
@rvagg However, landing this would result in another semver-major change I suppose. |
well, assuming this was an unintentional API change, it should be just a patch bugfix |
I think it would have to be treated as a regression and therefore a semver-patch. It's unfortunate because the original fix was trying to address a problem and this undoes that. But maybe there's an alternative path to addressing that problem that doesn't introduce a regression could be bundled along with a revert of the initial attempt. |
I note esbuild has also identified this as a problem. |
Same for webpack webpack/webpack#18891 This will fix #55609 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is the TLS test failure a known flaky?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Landed in 7b01758 |
This reverts commit 00b2f07. PR-URL: nodejs#55527 Fixes: nodejs#17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This reverts commit 00b2f07. PR-URL: #55527 Fixes: #17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This reverts commit 00b2f07. PR-URL: #55527 Fixes: #17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This reverts commit 00b2f07. PR-URL: nodejs#55527 Fixes: nodejs#17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
…6417 Looks like a nodejs bug, introduced in v23.0.0 - commit hash 00b2f07f It should be fixed in v23.2.0 - dd9b6833 bug: nodejs/node#54160 fix: nodejs/node#55527 I am able to replicate this on v23.1.0.
This reverts commit 00b2f07.
Reverts: #54160
Unfixes: #17801
Two problems with #54160 from my experience with things failing on v23:
open(2)
a directory and acts as ifO_DIRECTORY
has been supplied, which it hasn't. It's always been possible tofs.open()
a directory and use the file descriptor for it. If I happen to pass a trailing slash it shouldn't matter.Example of code broken on v23 that's worked up until now:
/cc @huseyinacacak-janea @mcollina @anonrig